package com.ladybug.flow.common.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ladybug.flow.common.exception.enums.ErrorEnum;

/**
* @description: 返回值封装
* @author long
* @date 2022/10/14 14:30
* @version 1.0
*/

public class ResponseResult <T> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息，如果有错误时，前端可以获取该字段进行提示
     */
    private String msg;
    /**
     * 查询到的结果数据，
     */
    private T data;

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(Integer code, T data) {
        this.code = code;
        this.data = data;
    }
    public ResponseResult(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static <T> ResponseResult<T> error(ErrorEnum errorEnum) {
        return new ResponseResult(errorEnum.getCode(), errorEnum.getMsg());
    }
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult(200, data);
    }
    public static <T> ResponseResult<T> error(int code,String msg) {
        return new ResponseResult(code, msg);
    }
    public static <T> ResponseResult<T> success() {
        return new ResponseResult(200);
    }

    public static <T> ResponseResult<T> success(String msg) {
        return new ResponseResult(200,msg);
    }
}
